package com.xz.main;

import org.apache.http.Consts;
import org.apache.http.HttpHost;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by YLZX-Z0107 on 2014/9/12.
 */
public class Main2 {
    public static void main(String[] args) throws Exception {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost post = new HttpPost("http://www.huafangwang.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1");
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("fastloginfield", "username"));
        formparams.add(new BasicNameValuePair("username", "QQ8983"));
        formparams.add(new BasicNameValuePair("password", "QQ8983"));
        formparams.add(new BasicNameValuePair("quickforward", "yes"));
        formparams.add(new BasicNameValuePair("handlekey", "ls"));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8);
        post.setEntity(entity);

//        HttpHost proxy = new HttpHost("221.176.14.72", 80);
//        RequestConfig config = RequestConfig.custom().setProxy(proxy).setSocketTimeout(5000)
//                .setConnectTimeout(5000).build();
//        post.setConfig(config);


        CloseableHttpResponse response = httpclient.execute(post);
        String result = EntityUtils.toString(response.getEntity(), "gbk");
        System.out.println(result);
    }
}
